what's the javascript "var _gaq = _gaq || []; " for ?

Posted by parvas on Stack Overflow See other posts from Stack Overflow or by parvas
Published on 2010-03-29T13:40:22Z Indexed on 2010/03/29 13:43 UTC
Read the original article Hit count: 125

The Async Tracking in google analytics looks like this:

var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-XXXXX-X']); _gaq.push(['_trackPageview']);

(function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();

About The first line

var _gaq = _gaq || [];

I think it ensures that if _gaq is already defined we should use it otherwise we should an array. Can anybody explain what this is for ?

Also, does it matter if _gaq gets renamed ? in other words does google analytics rely on a global object named _gaq ?

Thanks Parvas

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about google-analytics